*******************************************************************************************
* Replication file for:
* Anna Bruederle and Roland Hodler
* "Effect of oil spills on infant mortality in Nigeria"
* Proceedings of the National Academy of Sciences, 2019
*******************************************************************************************

set matsize 800
*Adjust directory
global path "D:\1. RESEARCH\Nigeria\Dataverse"
cd "$path"
set more off

********************************************************************************
* Table 1. Summary statistics
********************************************************************************

use "$path\DHS_oilspills_final.dta", clear

sum imr pmr if (v008-b3>12) & b2>=2006 & oilspills10km>0 & pregninfoonly!=1 & !missing(imr)
sum nmr oilspill_preconc_max10km if (v008-b3>1) & b2>=2006 & oilspills10km>0 & pregninfoonly!=1 & !missing(nmr)

********************************************************************************
* Table 2. Main results
********************************************************************************

use "$path\DHS_oilspills_final.dta", clear
set more off

xtset motherid babycount
global controls i.babycount mother10-mother45 precbirth1-precbirth3 multiple i.b2 i.b4

reg imr oilspill_preconc_max10km $controls if b2>=2006 & (v008-b3>12) & oilspills10km>0,  cluster(v001)
outreg2 using t2, tex excel replace dec(2) nocons keep(*spill*) addtext(Cluster FE, no, Birth characteristics, no, Cluster-specific time trend, no, Mother FE, no)
reg imr oilspill_preconc_max10km $controls i.v001 c.b2#i.v001 if b2>=2006 & (v008-b3>12) & oilspills10km>0,  cluster(v001)
outreg2 using t2, tex excel append dec(2) nocons keep(*spill*) addtext(Cluster FE, yes, Birth characteristics, yes, Cluster-specific time trend, yes, Mother FE, no)
xtreg imr oilspill_preconc_max10km $controls c.b2#i.v001 if b2>=2006 & (v008-b3>12) & oilspills10km>0, fe cluster(v001)
outreg2 using t2, tex excel append dec(2) nocons keep(*spill*) addtext(Cluster FE, no, Birth characteristics, yes, Cluster-specific time trend, yes, Mother FE, yes)
xtreg nmr oilspill_preconc_max10km $controls c.b2#i.v001 if b2>=2006 & (v008-b3>12) & oilspills10km>0, fe cluster(v001)
outreg2 using t2, tex excel append dec(2) nocons keep(*spill*) addtext(Cluster FE, no, Birth characteristics, yes, Cluster-specific time trend, yes, Mother FE, yes)
xtreg pmr oilspill_preconc_max10km $controls c.b2#i.v001 if b2>=2006 & (v008-b3>12) & oilspills10km>0, fe cluster(v001)
outreg2 using t2, tex excel append dec(2) nocons keep(*spill*) addtext(Cluster FE, no, Birth characteristics, yes, Cluster-specific time trend, yes, Mother FE, yes)
xtreg nmr oilspill_preconc_max10km $controls c.b2#i.v001 if b2>=2006 & (v008-b3>1) & oilspills10km>0, fe cluster(v001)
outreg2 using t2, tex excel append dec(2) nocons keep(*spill*) addtext(Cluster FE, no, Birth characteristics, yes, Cluster-specific time trend, yes, Mother FE, yes)

*Cluster count: 
keep if (v008-b3>1) & b2>=2006 & oilspills10km>0
bysort v001: gen clustercount =_n
count if clustercount==1 //130

********************************************************************************
* Fig. 2. Effect heterogeneneity
********************************************************************************

use "$path\DHS_oilspills_final.dta", clear

gen treated_boy=0
replace treated_boy=oilspill_preconc_max10km if b4==1
gen treated_girl=0
replace treated_girl=oilspill_preconc_max10km if b4==2

gen treated_seceduc=0
replace treated_seceduc=oilspill_preconc_max10km if seceduc==1
gen treated_loweduc=0
replace treated_loweduc=oilspill_preconc_max10km if loweduc==1

gen treated_rich=0
replace treated_rich=oilspill_preconc_max10km if poor==0
gen treated_poor=0
replace treated_poor=oilspill_preconc_max10km if poor==1

gen treated_urban=0
replace treated_urban=oilspill_preconc_max10km if urban==1
gen treated_rural=0
replace treated_rural=oilspill_preconc_max10km if urban==0

gen treated_nigerdelta=0
replace treated_nigerdelta=oilspill_preconc_max10km if nigerdelta==1
gen treated_elsewhere=0
replace treated_elsewhere=oilspill_preconc_max10km if nigerdelta==0

gen treated_conflict_yes=0
replace treated_conflict_yes=oilspill_preconc_max10km if conflict25==1
gen treated_conflict_no=0
replace treated_conflict_no=oilspill_preconc_max10km if conflict25==0

label variable treated_boy "Male"
label variable treated_girl "Female"
label variable treated_seceduc "Secondary education"
label variable treated_loweduc "No secondary education"
label variable treated_poor "Poor household"
label variable treated_rich "Non-poor household"
label variable treated_urban "Urban"
label variable treated_rural "Rural"
label variable treated_nigerdelta "Niger Delta"
label variable treated_elsewhere "Outside Niger Delta"
label variable treated_conflict_yes "Conflict area"
label variable treated_conflict_no "No conflict area"

xtset motherid babycount
global controls i.babycount mother10-mother45 precbirth1-precbirth3 multiple i.b2 i.b4

quietly xtreg nmr treated_boy treated_girl $controls c.b2#i.v001 if b2>=2006 & (v008-b3>1) & oilspills10km>0, fe cluster(v001)
estimates store male
test treated_boy=treated_girl
quietly xtreg nmr treated_seceduc treated_loweduc $controls c.b2#i.v001 if b2>=2006 & (v008-b3>1) & oilspills10km>0, fe cluster(v001)
estimates store edu
test treated_seceduc=treated_loweduc
quietly xtreg nmr treated_rich treated_poor $controls c.b2#i.v001 if b2>=2006 & (v008-b3>1) & oilspills10km>0, fe cluster(v001)
estimates store poor
test treated_rich=treated_poor
quietly xtreg nmr treated_urban treated_rural $controls c.b2#i.v001 if b2>=2006 & (v008-b3>1) & oilspills10km>0, fe cluster(v001)
estimates store urban
test treated_urban=treated_rural
quietly xtreg nmr treated_nigerdelta treated_elsewhere $controls c.b2#i.v001 if b2>=2006 & (v008-b3>1) & oilspills10km>0, fe cluster(v001)
estimates store delta
test treated_nigerdelta=treated_elsewhere
quietly xtreg nmr treated_conflict* $controls c.b2#i.v001 if b2>=2006 & (v008-b3>1) & oilspills10km>0, fe cluster(v001)
estimates store conflict
test treated_conflict_yes=treated_conflict_no

coefplot (male, msymbol(S)) (edu, msymbol(T)) (poor, msymbol(O)) (urban, msymbol(D)) (delta, msymbol(Sh)) (conflict, msymbol(Th)), keep(treated_*) ///
	xline(0) xlabel(-40[40]120) msymbol(D) mlabel format(%9.0f) mlabposition(12) legend(order(0 "Regression:" 2 "1" 4 "2" 6 "3" 8 "4" 10 "5" 12 "6") row(1)) ///
	headings(treated_boy = "{bf: Panel A}" treated_nigerdelta= "{bf: Panel B}", labcolor(orange))
graph export "$path\fig2.eps", replace

********************************************************************************
* Fig. S2. Pre-treatment trends
********************************************************************************

*Top graph
use "$path\DHS_oilspills_final.dta", clear
keep if b2>=2006 & (v008-b3>1) & oilspills10km>0 

gen birth_spill10km_minus=.
foreach d of numlist 1(1)5 {
	replace birth_spill10km_minus=-`d' if birth_spill10km_minus`d'==1
	local d_1 = `d'-1
	label variable birth_spill10km_minus`d' "`d_1'-`d' y"
	}

collapse imr nmr birth_spill10km_minus1-birth_spill10km_minus5, by(birth_spill10km_minus)
twoway connected imr birth_spill10km_minus, msymbol(D) ytitle("") xtitle("") xlabel(-1 "0-1 y" -2 "1-2 y" -3 "2-3 y" -4 "3-4 y" -5 "4-5 y") ylabel(0[20]80) saving(Fig_pretrends_imr_raw, replace)
twoway connected nmr birth_spill10km_minus, msymbol(D) ytitle("") xtitle("") xlabel(-1 "0-1 y" -2 "1-2 y" -3 "2-3 y" -4 "3-4 y" -5 "4-5 y") ylabel(0[20]80) saving(Fig_pretrends_nmr_raw, replace)

*Bottom graphs
use "$path\DHS_oilspills_final.dta", clear
set more off

foreach d of numlist 1(1)5 {
	local d_1 = `d'-1
	label variable birth_spill10km_minus`d' "`d_1'-`d' y"
	}

xtset motherid babycount	
global controls i.babycount mother10-mother45 precbirth1-precbirth3 multiple i.b2 i.b4

xtreg imr birth_spill10km_minus5 birth_spill10km_minus4 birth_spill10km_minus3 birth_spill10km_minus2 birth_spill10km_minus1 $controls c.b2#i.v001 ///
	if  b2>=2006 & (v008-b3>12) & oilspills10km>0 & oilspill_preconc_max10km==0, fe cluster(v001)	
test birth_spill10km_minus1=birth_spill10km_minus2
test birth_spill10km_minus2=birth_spill10km_minus3
test birth_spill10km_minus3=birth_spill10km_minus4
test birth_spill10km_minus4=birth_spill10km_minus5
coefplot, keep(birth_spill10km_minus*) vertical yline(0) ylabel(-100[50]100) msymbol(D) mlabel format(%9.0f) mlabposition(3) mlabgap(*2) saving(Fig_pretrends_imr_full, replace)
xtreg nmr birth_spill10km_minus5 birth_spill10km_minus4 birth_spill10km_minus3 birth_spill10km_minus2 birth_spill10km_minus1 $controls c.b2#i.v001 ///
	if  b2>=2006 & (v008-b3>12) & oilspills10km>0 & oilspill_preconc_max10km==0, fe cluster(v001)	
test birth_spill10km_minus1=birth_spill10km_minus2
test birth_spill10km_minus2=birth_spill10km_minus3
test birth_spill10km_minus3=birth_spill10km_minus4
test birth_spill10km_minus4=birth_spill10km_minus5
coefplot, keep(birth_spill10km_minus*) vertical yline(0) ylabel(-100[50]100) msymbol(D) mlabel format(%9.0f) mlabposition(3) mlabgap(*2) saving(Fig_pretrends_nmr_full, replace)

graph combine "Fig_pretrends_imr_raw" "Fig_pretrends_nmr_raw" "Fig_pretrends_imr_full" "Fig_pretrends_nmr_full", rows(2) cols(2) ysize(7) xsize(10)
graph export "$path/figS2.eps", replace
graph export "$path/figS2.pdf", replace

********************************************************************************
* Fig. S3. Disaggregation in time
********************************************************************************

use "$path\DHS_oilspills_final.dta", clear
set more off

label variable latest_1to12mpreconc "0-1 y"
label variable latest_13to24mpreconc "1-2 y"
label variable latest_25to36mpreconc "2-3 y"
label variable latest_37to48mpreconc "3-4 y"
label variable latest_49to60mpreconc "4-5 y"
gen latest_1to60mpreconc=latest_1to12mpreconc+latest_13to24mpreconc+latest_25to36mpreconc+latest_37to48mpreconc+latest_49to60mpreconc

xtset motherid babycount
global controls i.babycount mother10-mother45 precbirth1-precbirth3 multiple i.b2 i.b4

xtreg nmr latest_1to12mpreconc-latest_49to60mpreconc $controls c.b2#i.v001 if b2>=2006 & (v008-b3>1) & oilspills10km>0 & (latest_1to60mpreconc==1 | oilspill_preconc_max10km==0), fe cluster(v001)

coefplot, keep(latest_*) vertical yline(0) ylabel(0[40]120) msymbol(D) mlabel format(%9.0f) mlabposition(3) mlabgap(*2)
graph export "$path\figS3.pdf", replace
graph export "$path\figS3.eps", replace

********************************************************************************
* Fig. S4. Disaggregation in space
********************************************************************************

use "$path\DHS_oilspills_final.dta", clear
set more off
foreach d of numlist 1(1)15 {
	local d_1 = `d'-1
	label variable closestoilspill_preconc_`d' "`d'"
	}
	
xtset motherid babycount
global controls i.babycount mother10-mother45 precbirth1-precbirth3 multiple i.b2 i.b4
	
xtreg nmr closestoilspill_preconc_1-closestoilspill_preconc_15 c.b2#i.v001 $controls if b2>=2006 & (v008-b3>1) & oilspills15km>0, fe cluster(v001)
coefplot, keep(closestoilspill_*) vertical xtitle("Distance in km") yline(0) ylabel(-80[40]240) msymbol(D) mlabel format(%9.0f) mlabposition(3) mlabgap(*2)
graph export "$path\figS4.eps", replace
graph export "$path\figS4.pdf", replace

********************************************************************************
* Table S1. Summary statistics
********************************************************************************

use "$path\DHS_oilspills_final.dta", clear

sum oilspill_preconc_max10km oilspill_pregnancy_max10km oilspill_firsttrimester_max10km oilspill_2_3trimester_max10km nmr boy b11 multiple mothersage secedu poor urban nigerdelta conflict25 if (v008-b3>1) & b2>=2006 & oilspills10km>0 & pregninfoonly!=1 & !missing(nmr)
sum imr pmr if (v008-b3>12) & b2>=2006 & oilspills10km>0 & pregninfoonly!=1 & !missing(imr)
sum ptr if b2>=2008 & oilspills10km>0

********************************************************************************
* Table S2. Effects of oil spills during pregnancy
********************************************************************************

use "$path\DHS_oilspills_final.dta", clear
set more off

xtset motherid babycount
global controls i.babycount mother10-mother45 precbirth1-precbirth3 multiple i.b2 i.b4

*Panel A
reg imr oilspill_pregnancy_max10km $controls if b2>=2006 & (v008-b3>12) & oilspills10km>0,  cluster(v001)
outreg2 using ts2a, tex excel replace dec(2) nocons keep(*spill*) addtext(Cluster FE, no, Birth characteristics, no, Cluster-specific time trend, no, Mother FE, no)
reg imr oilspill_pregnancy_max10km $controls i.v001 c.b2#i.v001 if b2>=2006 & (v008-b3>12) & oilspills10km>0,  cluster(v001)
outreg2 using ts2a, tex excel append dec(2) nocons keep(*spill*) addtext(Cluster FE, yes, Birth characteristics, yes, Cluster-specific time trend, yes, Mother FE, no)
xtreg imr oilspill_pregnancy_max10km $controls c.b2#i.v001 if b2>=2006 & (v008-b3>12) & oilspills10km>0, fe cluster(v001)
outreg2 using ts2a, tex excel append dec(2) nocons keep(*spill*) addtext(Cluster FE, no, Birth characteristics, yes, Cluster-specific time trend, yes, Mother FE, yes)
xtreg nmr oilspill_pregnancy_max10km $controls c.b2#i.v001 if b2>=2006 & (v008-b3>12) & oilspills10km>0, fe cluster(v001)
outreg2 using ts2a, tex excel append dec(2) nocons keep(*spill*) addtext(Cluster FE, no, Birth characteristics, yes, Cluster-specific time trend, yes, Mother FE, yes)
xtreg pmr oilspill_pregnancy_max10km $controls c.b2#i.v001 if b2>=2006 & (v008-b3>12) & oilspills10km>0, fe cluster(v001)
outreg2 using ts2a, tex excel append dec(2) nocons keep(*spill*) addtext(Cluster FE, no, Birth characteristics, yes, Cluster-specific time trend, yes, Mother FE, yes)
xtreg nmr oilspill_pregnancy_max10km $controls c.b2#i.v001 if b2>=2006 & (v008-b3>1) & oilspills10km>0, fe cluster(v001)
outreg2 using ts2a, tex excel append dec(2) nocons keep(*spill*) addtext(Cluster FE, no, Birth characteristics, yes, Cluster-specific time trend, yes, Mother FE, yes)

*Panel B
reg imr oilspill_firsttrimester_max10km oilspill_2_3trimester_max10km $controls if b2>=2006 & (v008-b3>12) & oilspills10km>0,  cluster(v001)
outreg2 using ts2b, tex excel replace dec(2) nocons keep(*spill*) addtext(Cluster FE, no, Birth characteristics, no, Cluster-specific time trend, no, Mother FE, no)
reg imr oilspill_firsttrimester_max10km oilspill_2_3trimester_max10km $controls i.v001 c.b2#i.v001 if b2>=2006 & (v008-b3>12) & oilspills10km>0,  cluster(v001)
outreg2 using ts2b, tex excel append dec(2) nocons keep(*spill*) addtext(Cluster FE, yes, Birth characteristics, yes, Cluster-specific time trend, yes, Mother FE, no)
xtreg imr oilspill_firsttrimester_max10km oilspill_2_3trimester_max10km $controls c.b2#i.v001 if b2>=2006 & (v008-b3>12) & oilspills10km>0, fe cluster(v001)
outreg2 using ts2b, tex excel append dec(2) nocons keep(*spill*) addtext(Cluster FE, no, Birth characteristics, yes, Cluster-specific time trend, yes, Mother FE, yes)
xtreg nmr oilspill_firsttrimester_max10km oilspill_2_3trimester_max10km $controls c.b2#i.v001 if b2>=2006 & (v008-b3>12) & oilspills10km>0, fe cluster(v001)
outreg2 using ts2b, tex excel append dec(2) nocons keep(*spill*) addtext(Cluster FE, no, Birth characteristics, yes, Cluster-specific time trend, yes, Mother FE, yes)
xtreg pmr oilspill_firsttrimester_max10km oilspill_2_3trimester_max10km $controls c.b2#i.v001 if b2>=2006 & (v008-b3>12) & oilspills10km>0, fe cluster(v001)
outreg2 using ts2b, tex excel append dec(2) nocons keep(*spill*) addtext(Cluster FE, no, Birth characteristics, yes, Cluster-specific time trend, yes, Mother FE, yes)
xtreg nmr oilspill_firsttrimester_max10km oilspill_2_3trimester_max10km $controls c.b2#i.v001 if b2>=2006 & (v008-b3>1) & oilspills10km>0, fe cluster(v001)
outreg2 using ts2b, tex excel append dec(2) nocons keep(*spill*) addtext(Cluster FE, no, Birth characteristics, yes, Cluster-specific time trend, yes, Mother FE, yes)

*Panel C
reg imr oilspill_preconc_max10km oilspill_pregnancy_max10km $controls if b2>=2006 & (v008-b3>12) & oilspills10km>0,  cluster(v001)
outreg2 using ts2c, tex excel replace dec(2) nocons keep(*spill*) addtext(Cluster FE, no, Birth characteristics, no, Cluster-specific time trend, no, Mother FE, no)
reg imr oilspill_preconc_max10km oilspill_pregnancy_max10km $controls i.v001 c.b2#i.v001 if b2>=2006 & (v008-b3>12) & oilspills10km>0,  cluster(v001)
outreg2 using ts2c, tex excel append dec(2) nocons keep(*spill*) addtext(Cluster FE, yes, Birth characteristics, yes, Cluster-specific time trend, yes, Mother FE, no)
xtreg imr oilspill_preconc_max10km oilspill_pregnancy_max10km $controls c.b2#i.v001 if b2>=2006 & (v008-b3>12) & oilspills10km>0, fe cluster(v001)
outreg2 using ts2c, tex excel append dec(2) nocons keep(*spill*) addtext(Cluster FE, no, Birth characteristics, yes, Cluster-specific time trend, yes, Mother FE, yes)
xtreg nmr oilspill_preconc_max10km oilspill_pregnancy_max10km $controls c.b2#i.v001 if b2>=2006 & (v008-b3>12) & oilspills10km>0, fe cluster(v001)
outreg2 using ts2c, tex excel append dec(2) nocons keep(*spill*) addtext(Cluster FE, no, Birth characteristics, yes, Cluster-specific time trend, yes, Mother FE, yes)
xtreg pmr oilspill_preconc_max10km oilspill_pregnancy_max10km $controls c.b2#i.v001 if b2>=2006 & (v008-b3>12) & oilspills10km>0, fe cluster(v001)
outreg2 using ts2c, tex excel append dec(2) nocons keep(*spill*) addtext(Cluster FE, no, Birth characteristics, yes, Cluster-specific time trend, yes, Mother FE, yes)
xtreg nmr oilspill_preconc_max10km oilspill_pregnancy_max10km $controls c.b2#i.v001 if b2>=2006 & (v008-b3>1) & oilspills10km>0, fe cluster(v001)
outreg2 using ts2c, tex excel append dec(2) nocons keep(*spill*) addtext(Cluster FE, no, Birth characteristics, yes, Cluster-specific time trend, yes, Mother FE, yes)

********************************************************************************
* Table S3: Effect on pregnancy terminations
********************************************************************************

use "$path\DHS_oilspills_final.dta", clear
set more off

xtset motherid babycount
global controls2 mother10-mother45 i.conception_y

reg ptr oilspill_preconc_max10km $controls2 if conception_y>=2008 & oilspills10km>0 & conception_CMC<=v008-10, cluster(v001)
outreg2 using ts3, tex excel replace dec(2) nocons keep(*spill*) addtext(Cluster FE, no, Birth characteristics, yes, Cluster-specific time trend, no, Mother FE, no)
reg ptr oilspill_preconc_max10km $controls2 i.v001 c.conception_y#i.v001 if conception_y>=2008 & oilspills10km>0 & conception_CMC<=v008-10, cluster(v001)
outreg2 using ts3, tex excel append dec(2) nocons keep(*spill*) addtext(Cluster FE, yes, Birth characteristics, yes, Cluster-specific time trend, yes, Mother FE, no)
xtreg ptr oilspill_preconc_max10km $controls2 c.conception_y#i.v001 if conception_y>=2008 & oilspills10km>0 & conception_CMC<=v008-10, fe cluster(v001)
outreg2 using ts3, tex excel append dec(2) nocons keep(*spill*) addtext(Cluster FE, yes, Birth characteristics, yes, Cluster-specific time trend, yes, Mother FE, yes)
